package cn.btks.resultintegration.catalog.repository;

import cn.btks.resultintegration.catalog.pojo.PolicyFile;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author lijun
 * @Date 2020/12/17 12:41
 */
@Repository
public interface PolicyFileRepository extends JpaRepository<PolicyFile,Long> {

    /**
     * 根据文件名查询所有文件
     * @param fileName
     * @return
     */
    @Query(value = "select * from policy_file where file_name like '%' ?1 '%'",nativeQuery = true)
    List<PolicyFile> findAllByFileName(String fileName);

    /**
     * 根据目录ID查询政策文件
     * @param catalogId
     * @return
     */@Query(value = "select * from policy_file where catalog_id = ?1 ",nativeQuery = true)
    List<PolicyFile> findAllByCatalogId(Long catalogId);

    /**
     * 根据目录ID删除政策文件
     * @param catalog_id
     * @param typeId
     * @return
     */
    @Modifying
    @Query(value = "delete from policy_file where catalog_id = ?1",nativeQuery = true)
    int deleteByCatalogId(Long catalogId);
}
